home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / POINT_SN.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  12.3 KB  |  322 lines

  1.  
  2. package sub_arctic.lib;
  3.  
  4. import sub_arctic.input.snap_targetable;
  5. import sub_arctic.input.snap_draggable;
  6. import sub_arctic.input.snap_drag_agent;
  7. import sub_arctic.input.int_holder;
  8. import sub_arctic.input.event;
  9.  
  10. import java.awt.Image;
  11. import java.awt.Point;
  12.  
  13. /**
  14.  * This Class implements a point snap target.  The target point is defined to
  15.  * lie in the center of the object.  It does no drawing nor does it limit the 
  16.  * class of drag objects that snap to it, or do anything when the snap occurs 
  17.  * (all these additional behaviors would normally be added in a subclass).
  18.  * See the documentation in the snap-drag agent for full details of how 
  19.  * snapping works.
  20.  *
  21.  * @see sub_arctic.input.snap_drag_agent
  22.  * @author Scott Hudson
  23.  */
  24. public class point_snap_target 
  25.   extends base_interactor implements snap_targetable {
  26.  
  27.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  28.  
  29.   /** 
  30.    * Constructor.
  31.    * @param int x the x coordinate of the snap target point.
  32.    * @param int y the y coordinate of the snap target point.
  33.    */
  34.   public point_snap_target(int x, int y)
  35.     {
  36.       super(x,y, 1,1);
  37.     }
  38.  
  39.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  40.   /* snap_targetable methods */
  41.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  42.     
  43.  
  44.   /** Determine if the given point (in local coordinates) is close enough
  45.    *  to snap to the point (and return the square of its distance, and 
  46.    *  the point snapped to).  This is a geometric test only.  It reports
  47.    *  a snap if the square of the distance to the point is less than or equal 
  48.    *  to snap_drag_agent.snap_dist2().  The object return_dist2 object is 
  49.    *  modified so that it contains the square of the distance from the drag 
  50.    *  point to the target point.  The return_snap_pt object is modified to 
  51.    *  return the position of the target point.  
  52.    *  
  53.    *  @param pt             the point being tested (in local coordinates).
  54.    *  @param return_dist2   modified to contain the square of the distance
  55.    *                        to the point.
  56.    *  @param return_snap_pt modified to contain the snap target point location
  57.    *                        in local coordinates (i.e., 0,0).
  58.    *  @return boolean indicating whether the snap is geometrically accepted.
  59.    */
  60.   public boolean point_snaps(
  61.     Point      pt, 
  62.     int_holder return_dist2, 
  63.     Point      return_snap_pt)
  64.     {
  65.       int dist, tx, ty;
  66.  
  67.       /* target point is at our center */
  68.       tx = w()/2; 
  69.       ty = h()/2;
  70.  
  71.       /* compute square of distance from target to drag point */
  72.       dist = (tx-pt.x)*(tx-pt.x) + (ty-pt.y)*(ty-pt.y);
  73.  
  74.       /* do we snap? */
  75.       if (dist <= snap_drag_agent.snap_dist2())
  76.     {
  77.       /* return our values + success */
  78.       return_dist2.value = dist;
  79.       return_snap_pt.x = tx;
  80.       return_snap_pt.y = ty;
  81.  
  82.       return true;
  83.     }
  84.       else
  85.     return false;
  86.     }
  87.  
  88.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  89.  
  90.   /** Determine if a geometrically accepted snap should be semantically 
  91.    *  accepted.  In this case we accept all snaps.
  92.    *  
  93.    *  @param pt              the pre-snap location of the feature point being 
  94.    *                         tested.
  95.    *  @param drag_obj        the drag object being tested.
  96.    *  @param feature_pt_indx the index of the feature point (within drag_obj)
  97.    *                         being tested.
  98.    *  @return whether the snap is acceptable.
  99.    */
  100.   public boolean snap_from_ok(
  101.     Point          pt, 
  102.     snap_draggable drag_obj, 
  103.     int            feature_pt_indx)
  104.     {
  105.       return true;
  106.     }
  107.    
  108.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  109.  
  110.   /** Determine if a geometrically accepted snap which has been semantically
  111.    *  rejected (by snap_from_obj()) should provide anti-snap feedback.
  112.    *  In this case we never provide anti-snap feedback.
  113.    *
  114.    *  @param pt              the pre-snap location of the feature point being 
  115.    *                         tested.
  116.    *  @param drag_obj        the drag object being tested.
  117.    *  @param feature_pt_indx the index of the feature point (within drag_obj) 
  118.    *                         being tested.
  119.    *  @return null for no anti-snap.  if anti-snap feedback is desired a 
  120.    *   non-null object is returned (which is later passed to various anti-snap 
  121.    *   routines in the protocol).
  122.    */
  123.    public Object anti_snap_from_ok(
  124.     Point          pt, 
  125.     snap_draggable drag_obj, 
  126.     int            feature_pt_indx)
  127.     {
  128.       return null;
  129.     }
  130.  
  131.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  132.  
  133.   /** 
  134.    * Do the feedback corresponding to a snap from the given drag object.
  135.    * This class does no feedback, so this is accepted but ignored. 
  136.    *
  137.    * @param event evt      the event       that "caused the snap".
  138.    * @param Point orig_pt  the point       the dragged object would nominally 
  139.    *                                       be at.
  140.    * @param Point snap_pt  the point       the dragged object snaps to.
  141.    * @param snap_draggable drag_obj        the dragged object.
  142.    * @param int            feature_pt_indx the feature point within dragged 
  143.    *                                       object that we are snapping with.
  144.    * @param Object         user_info       the information that was associated 
  145.    *                                       with the dragged object when it 
  146.    *                                       requested snap-drag focus.
  147.    */
  148.   public boolean snap_from(
  149.     event          evt, 
  150.     Point          orig_pt, 
  151.     Point          snap_pt, 
  152.     snap_draggable drag_obj, 
  153.     int            feature_pt_indx,
  154.     Object         user_info)
  155.     {
  156.       return true;
  157.     }
  158.  
  159.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  160.  
  161.   /**
  162.    * Do feedback while a snap is active.
  163.    * 
  164.    * @param event evt      the event       that "caused the snap".
  165.    * @param Point orig_pt  the point       the dragged object would nominally 
  166.    *                                       be at.
  167.    * @param Point snap_pt  the point       the dragged object snaps to.
  168.    * @param snap_draggable drag_obj        the dragged object.
  169.    * @param int            feature_pt_indx the feature point within dragged 
  170.    *                                       object that we are snapping with.
  171.    * @param Object         user_info       the information that was associated 
  172.    *                                       with the dragged object when it 
  173.    *                                       requested snap-drag focus.
  174.    */
  175.   public boolean snap_feedback(
  176.     event          evt, 
  177.     Point          orig_pt, 
  178.     Point          snap_pt, 
  179.     snap_draggable drag_obj, 
  180.     int            feature_pt_indx,
  181.     Object         user_info)
  182.     {
  183.       return true;
  184.     }
  185.  
  186.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  187.  
  188.   /** 
  189.    * Remove feedback for a snap that is now being broken.  This class does 
  190.    * no feedback, so this is accepted but ignored.
  191.    * 
  192.    * @param event evt      the event       that "caused the snap".
  193.    * @param Point orig_pt  the point       the dragged object would nominally 
  194.    *                                       be at.
  195.    * @param Point snap_pt  the point       the dragged object snaps to.
  196.    * @param snap_draggable drag_obj        the dragged object.
  197.    * @param int            feature_pt_indx the feature point within dragged 
  198.    *                                       object that we are snapping with.
  199.    * @param Object         user_info       the information that was associated 
  200.    *                                       with the dragged object when it 
  201.    *                                       requested snap-drag focus.
  202.    */
  203.   public boolean unsnap_from(
  204.     event          evt, 
  205.     Point          orig_pt, 
  206.     Point          snap_pt, 
  207.     snap_draggable drag_obj, 
  208.     int            feature_pt_indx,
  209.     Object         user_info)
  210.     {
  211.       return true;
  212.     }
  213.     
  214.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  215.  
  216.   /** 
  217.    * Do anti-snap feedback corresponding to an anti-snap from the given 
  218.    * drag object.  This class does not do anti-snaps, so this is accepted 
  219.    * but ignored.
  220.    * 
  221.    * @param event evt      the event       that "caused the anti-snap".
  222.    * @param Point orig_pt  the point       the dragged object would nominally 
  223.    *                                       be at.
  224.    * @param Point snap_pt  the point       the dragged object anti-snaps to.
  225.    * @param snap_draggable drag_obj        the dragged object.
  226.    * @param int            feature_pt_indx the feature point within dragged 
  227.    *                                       object that we are anti-snapping 
  228.    *                                       with.
  229.    * @param Object         user_info       the information that was associated 
  230.    *                                       with the dragged object when it 
  231.    *                                       requested snap-drag focus.
  232.    */
  233.   public boolean anti_snap_from(
  234.     event          evt, 
  235.     Point          orig_pt, 
  236.     Point          snap_pt, 
  237.     snap_draggable drag_obj, 
  238.     int            feature_pt_indx,
  239.     Object         anti_snap_info,
  240.     Object         user_info)
  241.     {
  242.       return true;
  243.     }
  244.  
  245.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  246.  
  247.   /* 
  248.    * Do feedback while an anti-snap is in place.
  249.    * 
  250.    * @param event evt      the event       that "caused the anti-snap".
  251.    * @param Point orig_pt  the point       the dragged object would nominally 
  252.    *                                       be at.
  253.    * @param Point snap_pt  the point       the dragged object anti-snaps to.
  254.    * @param snap_draggable drag_obj        the dragged object.
  255.    * @param int            feature_pt_indx the feature point within dragged 
  256.    *                                       object that we are anti-snapping 
  257.    *                                       with.
  258.    * @param Object         user_info       the information that was associated 
  259.    *                                       with the dragged object when it 
  260.    *                                       requested snap-drag focus.
  261.    */
  262.   public boolean anti_snap_feedback(
  263.     event          evt, 
  264.     Point          orig_pt, 
  265.     Point          snap_pt, 
  266.     snap_draggable drag_obj, 
  267.     int            feature_pt_indx,
  268.     Object         anti_snap_info,
  269.     Object         user_info)
  270.     {
  271.       return true;
  272.     }
  273.  
  274.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  275.  
  276.   /** 
  277.    * Remove anti-snap feedback for an anti-snap that is now being broken.
  278.    * This class does not do anti-snaps, so this is accepted but ignored.
  279.    * 
  280.    * @param event evt      the event       that "caused the anti-snap".
  281.    * @param Point orig_pt  the point       the dragged object would nominally 
  282.    *                                       be at.
  283.    * @param Point snap_pt  the point       the dragged object anti-snaps to.
  284.    * @param snap_draggable drag_obj        the dragged object.
  285.    * @param int            feature_pt_indx the feature point within dragged 
  286.    *                                       object that we are anti-snapping 
  287.    *                                       with.
  288.    * @param Object         user_info       the information that was associated 
  289.    *                                       with the dragged object when it 
  290.    *                                       requested snap-drag focus.
  291.    */
  292.   public boolean unanti_snap_from(
  293.     event          evt, 
  294.     Point          orig_pt, 
  295.     Point          snap_pt, 
  296.     snap_draggable drag_obj, 
  297.     int            feature_pt_indx,
  298.     Object         anti_snap_info,
  299.     Object         user_info)
  300.     {
  301.       return true;
  302.     }
  303.  
  304.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  305. }
  306. /*=========================== COPYRIGHT NOTICE ===========================
  307.  
  308. This file is part of the subArctic user interface toolkit.
  309.  
  310. Copyright (c) 1996 Scott Hudson and Ian Smith
  311. All rights reserved.
  312.  
  313. The subArctic system is freely available for most uses under the terms
  314. and conditions described in 
  315.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  316. and appearing in full in the lib/interactor.java source file.
  317.  
  318. The current release and additional information about this software can be 
  319. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  320.  
  321. ========================================================================*/
  322.